package bali;

import java.lang.annotation.Annotation;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Element;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.DeclaredType;;
import freemarker.template.TemplateModelException;
import java.util.Set;

public class ValidationProcessor extends SimpleFreemarkerAnnotationProcessor {

	@Override
	protected String getGeneratedName(TypeElement element) {
		for (Element method : ((TypeElement)getAnnotationParameters(element, getAnnotationClass()).get("factoryInterface")).getEnclosedElements()) {
			if (method instanceof ExecutableElement &&
			 ((ExecutableElement)method).getSimpleName().contentEquals("create")) {
				VariableElement param = ((ExecutableElement)method).getParameters().get(0);
				return param.asType()+"DecoratorFactoryImpl";
			}
		}
		throw new RuntimeException("no create() method");
	}

	@Override
	protected Class<? extends Annotation> getAnnotationClass() {
		return Validation.class;
	}
}
